package com.hoas.distributedlock.core;

public class LockContext {

    private static ThreadLocal<DisributedLock> disributedLockThreadLocal = new ThreadLocal<DisributedLock>();

    public static DisributedLock getLock() {

        DisributedLock lock = disributedLockThreadLocal.get();

        if (lock == null) {
            lock = DisributedLockFactory.build();
            disributedLockThreadLocal.set( lock);
        }

        return lock;
    }

    public static void release() {
        getLock().release();
        disributedLockThreadLocal.remove();
    }

}
